package com.muse.designpatterns.composite;

public class CompositeTest {
    public static void main(String[] args) {
        AbstractCorp a = new BranchCorp("A","董事长",1000000);
        AbstractCorp b = new BranchCorp("B","技术总监",700000);
        AbstractCorp c = new BranchCorp("C","人事总监",600000);
        AbstractCorp d = new BranchCorp("D","财务总监",500000);

        AbstractCorp b1 = new BranchCorp("B1","程序员",30000);
        AbstractCorp b2 = new BranchCorp("B2","程序员",20000);
        AbstractCorp c1 = new BranchCorp("C1","HR",15000);
        AbstractCorp d1 = new BranchCorp("D1","会计",15000);

        a.addSubCorp(b,c,d);
        b.addSubCorp(b1,b2);
        c.addSubCorp(c1);
        d.addSubCorp(d1);

        System.out.println("a 的下属---------------");
        getSubCorp((BranchCorp) a);
        System.out.println("b 的下属---------------");
        getSubCorp((BranchCorp) b);

    }

    public static void getSubCorp(BranchCorp corp){
        for (AbstractCorp corp1 : corp.getSubCorp()){
            System.out.println("corp = "+ corp1.getCorpInfo());
            if (corp1 instanceof BranchCorp)
                getSubCorp((BranchCorp) corp1);
        }
    }
}
